package cn.shop.cloud.common;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @program: IntelliJ IDEA
 * @ClassName: Result
 * @description:结果返回类
 * @author: Song
 * @create: 2024-12-13 07 : 57
 * @version: 1.0
 **/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    private Integer code;//code码
    private String msg;//信息
    private T data;//数据

    public static  final int SUCCESS_CODE=200;
    public static  final String SUCCESS_MESSAGE="操作成功";

    public static  final int ERROR_CODE=500000;
    public static  final String ERROR_MESSAGE="系统异常";



    public static <T> Result<T> success(T data){
        return new Result<>(SUCCESS_CODE,SUCCESS_MESSAGE,data);
    }
    public static <T> Result<T> success(T data,String msg){
        return new Result<>(SUCCESS_CODE,SUCCESS_MESSAGE,data);
    }


    public static <T> Result<T> error(CodeMsg codeMsg){
        return new Result<>(codeMsg.getCode(),codeMsg.getMsg(),null);
    }
    public static <T> Result<T> defaultError(){
        return new Result<>(ERROR_CODE,ERROR_MESSAGE,null);
    }

    public boolean hasError(){
        return this.code!=SUCCESS_CODE;
    }


}
